<!doctype html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="MySQL," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.1" />






<meta name="description" content="一、环境&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;master：192.168.101&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MYSQL版本：5.1.48-community-log &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;slave">
<meta name="keywords" content="MySQL">
<meta property="og:type" content="article">
<meta property="og:title" content="mysql一主多从同步配置">
<meta property="og:url" content="https://hcldirgit.github.io/2017/09/03/MySQL/32. mysql一主多从同步配置/index.html">
<meta property="og:site_name" content="失落的乐章">
<meta property="og:description" content="一、环境&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;master：192.168.101&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MYSQL版本：5.1.48-community-log &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;slave">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2017-09-01T09:03:11.975Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="mysql一主多从同步配置">
<meta name="twitter:description" content="一、环境&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;master：192.168.101&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;MYSQL版本：5.1.48-community-log &amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;slave">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":0,"b2t":false,"scrollpercent":false},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://hcldirgit.github.io/2017/09/03/MySQL/32. mysql一主多从同步配置/"/>





  <title>mysql一主多从同步配置 | 失落的乐章</title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  




<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
            (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
          m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
  ga('create', '85*****1', 'auto');
  ga('send', 'pageview');
</script>


  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?87980c**************99ec5e26fb5";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>











  
  
    
  

  <div class="container sidebar-position-left page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">失落的乐章</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">技术面前，永远都是学生。</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-message">
          <a href="/message" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-external-link"></i> <br />
            
            留言
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">
    <link itemprop="mainEntityOfPage" href="https://hcldirgit.github.io/2017/09/03/MySQL/32. mysql一主多从同步配置/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="失落的乐章">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/0.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="失落的乐章">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">mysql一主多从同步配置</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-09-03T02:06:42+08:00">
                2017-09-03
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="一、环境"><a href="#一、环境" class="headerlink" title="一、环境"></a>一、环境</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;master：192.168.101<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MYSQL版本：5.1.48-community-log</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;slave1:192.168.2.182<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MYSQL版本：5.1.48-community-log</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;slave2:192.168.2.111<br>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;MYSQL版本：5.1.48-community-log</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;so…1 vs 2。</p>
<h2 id="二、master和-slave上的相关配置"><a href="#二、master和-slave上的相关配置" class="headerlink" title="二、master和 slave上的相关配置"></a>二、master和 slave上的相关配置</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;3台上都一样：</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>在/etc目录下可能无my.cnf文件，从/user/share/mysql目录中拷贝my-medium.cnf 到/etc并修改成my.cnf</strong></p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">[root@localhost etc]<span class="comment"># cp /usr/share/mysql/my-medium.cnf my.cnf</span></div><div class="line">[root@localhost etc]<span class="comment"># ll |grep my</span></div><div class="line">-rwxr-xr-x 1 root root 5204 Feb 13 22:52 my_bak</div><div class="line">-rwxr-xr-x 1 root root 4765 Jul 10 23:07 my.cnf</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;master 上;</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">[root@mysql101 ~]<span class="comment"># vi /etc/my.cnf</span></div></pre></td></tr></table></figure>
<h3 id="1-修改master上的配置文件my-cnf。"><a href="#1-修改master上的配置文件my-cnf。" class="headerlink" title="1.修改master上的配置文件my.cnf。"></a>1.修改master上的配置文件my.cnf。</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在[mysqld]下添加如下字段：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">server-id = 1</div><div class="line"><span class="built_in">log</span>-bin=mysql-bin</div><div class="line">binlog-do-db=YYY //需要同步的数据库</div><div class="line">binlog-ignore-db=mysql //被忽略的数据库</div><div class="line">binlog-ignore-db=information-schema //被忽略的数据库</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在master上为slave添加一个同步账号</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div></pre></td><td class="code"><pre><div class="line">mysql&gt; grant replication slave on *.* to <span class="string">'affairlog'</span>@<span class="string">'192.168.2.182'</span> identified by <span class="string">'pwd123'</span>;</div><div class="line">//在slave1上登陆成功</div><div class="line">mysql&gt; grant replication slave on *.* to <span class="string">'affairlog'</span>@<span class="string">'192.168.2.111'</span> identified by <span class="string">'pwd123'</span>;</div><div class="line">//在slave2上登陆成功</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后，重启master的mysql服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">service mysql restart;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;用show master status命令查看日志情况</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show master status\G;</div><div class="line">*************************** 1. row ***************************</div><div class="line">File: mysql-bin.000087</div><div class="line">Position: 106</div><div class="line">Binlog_Do_DB: YYY</div><div class="line">Binlog_Ignore_DB: mysql,information-schema</div><div class="line">1 row <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</div></pre></td></tr></table></figure>
<h3 id="2-修改slave1上的配置文件my-cnf。"><a href="#2-修改slave1上的配置文件my-cnf。" class="headerlink" title="2.修改slave1上的配置文件my.cnf。"></a>2.修改slave1上的配置文件my.cnf。</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在[mysqld]下添加如下字段</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div></pre></td><td class="code"><pre><div class="line">[root@mysql182 ~]<span class="comment"># vi /etc/my.cnf</span></div><div class="line">server-id=182</div><div class="line">master-host=192.168.3.101</div><div class="line">master-user= affairlog</div><div class="line">master-password=pwd123</div><div class="line">master-port=3306</div><div class="line">master-connect-retry=60</div><div class="line">replicate-do-db=YYY //同步的数据库</div><div class="line">replicate-ignore-db=mysql //被忽略的数据库</div><div class="line">replicate-ignore-db=information-schema //被忽略的数据库</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;保存后，重启slave的mysql服务：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">service mysql restart;</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;修改slave2上的配置文件my.cnf，和上面类似，只是把server-id改下，为了方便，我都用了相应的ip某位，</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;所以，slave2上我设置的server-id是111。</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;在进入两个slave机中的mysql。</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line">mysql&gt;start slave;</div><div class="line">mysql&gt;show slave status\G;</div><div class="line">*************************** 1. row ***************************</div><div class="line">Slave_IO_State: Waiting <span class="keyword">for</span> master to send event</div><div class="line">Master_Host: 192.168.3.101</div><div class="line">Master_User: affairlog</div><div class="line">Master_Port: 3306</div><div class="line">Connect_Retry: 60</div><div class="line">Master_Log_File: mysql-bin.000087</div><div class="line">Read_Master_Log_Pos: 106</div><div class="line">Relay_Log_File: vm111-relay-bin.000002</div><div class="line">Relay_Log_Pos: 251</div><div class="line">Relay_Master_Log_File: mysql-bin.000087</div><div class="line">Slave_IO_Running: Yes</div><div class="line">Slave_SQL_Running: Yes</div><div class="line">Replicate_Do_DB: YYY</div><div class="line">Replicate_Ignore_DB: mysql,information-schema</div><div class="line">Replicate_Do_Table:</div><div class="line">Replicate_Ignore_Table:</div><div class="line">Replicate_Wild_Do_Table:</div><div class="line">Replicate_Wild_Ignore_Table:</div><div class="line">Last_Errno: 0</div><div class="line">Last_Error:</div><div class="line">Skip_Counter: 0</div><div class="line">Exec_Master_Log_Pos: 106</div><div class="line">Relay_Log_Space: 406</div><div class="line">Until_Condition: None</div><div class="line">Until_Log_File:</div><div class="line">Until_Log_Pos: 0</div><div class="line">Master_SSL_Allowed: No</div><div class="line">Master_SSL_CA_File:</div><div class="line">Master_SSL_CA_Path:</div><div class="line">Master_SSL_Cert:</div><div class="line">Master_SSL_Cipher:</div><div class="line">Master_SSL_Key:</div><div class="line">Seconds_Behind_Master: 0</div><div class="line">Master_SSL_Verify_Server_Cert: No</div><div class="line">Last_IO_Errno: 0</div><div class="line">Last_IO_Error:</div><div class="line">Last_SQL_Errno: 0</div><div class="line">Last_SQL_Error:</div><div class="line">1 row <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<strong>如果两个slave中的Slave_IO_Running、Slave_SQL_Running状态均为Yes则表明设置成功。</strong></p>
<h2 id="三、可能遇到的问题："><a href="#三、可能遇到的问题：" class="headerlink" title="三、可能遇到的问题："></a>三、可能遇到的问题：</h2><h3 id="问题1：Slave-IO-Running-No或者Slave-SQL-Running-No"><a href="#问题1：Slave-IO-Running-No或者Slave-SQL-Running-No" class="headerlink" title="问题1：Slave_IO_Running: No或者Slave_SQL_Running: No"></a>问题1：Slave_IO_Running: No或者Slave_SQL_Running: No</h3><h4 id="停掉slave服务"><a href="#停掉slave服务" class="headerlink" title="停掉slave服务"></a>停掉slave服务</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; slave stop;</div><div class="line">Query OK, 0 rows affected (2.01 sec)</div></pre></td></tr></table></figure>
<h4 id="解决办法"><a href="#解决办法" class="headerlink" title="解决办法"></a>解决办法</h4><ol>
<li>在master上查看。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">mysql&gt; show master status\G;</div><div class="line">*************************** 1. row ***************************</div><div class="line">File: mysql-bin.000087</div><div class="line">Position: 1845</div><div class="line">Binlog_Do_DB: YYY</div><div class="line">Binlog_Ignore_DB: mysql,information-schema</div><div class="line">1 row <span class="keyword">in</span> <span class="built_in">set</span> (0.00 sec)</div></pre></td></tr></table></figure>
<ol>
<li>到slave上手动同步。</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">mysql&gt;change master to</div><div class="line">&gt;master_host=<span class="string">'192.168.3.101'</span>,</div><div class="line">&gt;master_user=<span class="string">'affairlog'</span>,</div><div class="line">&gt;master_password=<span class="string">'pwd123'</span>,</div><div class="line">&gt;master_log_file=<span class="string">'mysql-bin.000087'</span>,</div><div class="line">&gt;master_log_pos=1845;</div><div class="line">Query OK, 0 rows affected (0.00 sec)</div></pre></td></tr></table></figure>
<h4 id="启动slave服务"><a href="#启动slave服务" class="headerlink" title="启动slave服务"></a>启动slave服务</h4><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; slave start;</div></pre></td></tr></table></figure>
<h4 id="再次查看Slave-IO-Running、Slave-SQL-Running状态，为Yes则表明设置成功。"><a href="#再次查看Slave-IO-Running、Slave-SQL-Running状态，为Yes则表明设置成功。" class="headerlink" title="再次查看Slave_IO_Running、Slave_SQL_Running状态，为Yes则表明设置成功。"></a>再次查看Slave_IO_Running、Slave_SQL_Running状态，为Yes则表明设置成功。</h4><h3 id="问题2：RROR-1198-HY000-This-operation-cannot-be-performed-with-a-running-slave-run-STOP-SLAVE-first"><a href="#问题2：RROR-1198-HY000-This-operation-cannot-be-performed-with-a-running-slave-run-STOP-SLAVE-first" class="headerlink" title="问题2：RROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first"></a>问题2：RROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;错误重现：</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">mysql&gt;change master to</div><div class="line">&gt;master_host=<span class="string">'192.168.3.101'</span>,</div><div class="line">&gt;master_user=<span class="string">'affairlog'</span>,</div><div class="line">&gt;master_password=<span class="string">'pwd123'</span>,</div><div class="line">&gt;master_log_file=<span class="string">'mysql-bin.000087'</span>,</div><div class="line">&gt;master_log_pos=1845;</div><div class="line">ERROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决方法：</p>
<ol>
<li>停掉slave服务</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; slave stop;</div><div class="line">Query OK, 0 rows affected (2.01 sec)</div></pre></td></tr></table></figure>
<ol>
<li>重置slave服务</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div></pre></td><td class="code"><pre><div class="line">mysql&gt; reset stop;</div><div class="line">Query OK, 0 rows affected (2.01 sec)</div></pre></td></tr></table></figure>
<ol>
<li>再执行一次change命令</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">mysql&gt;change master to</div><div class="line">&gt;master_host=<span class="string">'192.168.3.101'</span>,</div><div class="line">&gt;master_user=<span class="string">'affairlog'</span>,</div><div class="line">&gt;master_password=<span class="string">'pwd123'</span>,</div><div class="line">&gt;master_log_file=<span class="string">'mysql-bin.000087'</span>,</div><div class="line">&gt;master_log_pos=1845;</div><div class="line">Query OK, 0 rows affected (0.00 sec)</div></pre></td></tr></table></figure>
<ol>
<li>启动slave服务</li>
</ol>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql&gt; slave start;</div></pre></td></tr></table></figure>
<p>5．再次查看Slave_IO_Running、Slave_SQL_Running状态，为Yes则表明设置成功。</p>
<h3 id="PS："><a href="#PS：" class="headerlink" title="PS："></a>PS：</h3><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Slave_IO_Running：连接到主库，并读取主库的日志到本地，生成本地日志文件</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Slave_SQL_Running:读取本地日志文件，并执行日志里的SQL命令。</p>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/MySQL/" rel="tag"># MySQL</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/09/03/MySQL/31. mysql5.1的RBR和SBR的优缺点/" rel="next" title="mysql5.1的RBR和SBR的优缺点">
                <i class="fa fa-chevron-left"></i> mysql5.1的RBR和SBR的优缺点
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/09/03/MySQL/33. mysql主从数据库不同步的2种解决方法/" rel="prev" title="mysql主从数据库不同步的2种解决方法">
                mysql主从数据库不同步的2种解决方法 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/0.png"
               alt="失落的乐章" />
          <p class="site-author-name" itemprop="name">失落的乐章</p>
           
              <p class="site-description motion-element" itemprop="description">失落的乐章的Blog</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/">
                <span class="site-state-item-count">627</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/hcldirgit" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#一、环境"><span class="nav-number">1.</span> <span class="nav-text">一、环境</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#二、master和-slave上的相关配置"><span class="nav-number">2.</span> <span class="nav-text">二、master和 slave上的相关配置</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-修改master上的配置文件my-cnf。"><span class="nav-number">2.1.</span> <span class="nav-text">1.修改master上的配置文件my.cnf。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-修改slave1上的配置文件my-cnf。"><span class="nav-number">2.2.</span> <span class="nav-text">2.修改slave1上的配置文件my.cnf。</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#三、可能遇到的问题："><span class="nav-number">3.</span> <span class="nav-text">三、可能遇到的问题：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#问题1：Slave-IO-Running-No或者Slave-SQL-Running-No"><span class="nav-number">3.1.</span> <span class="nav-text">问题1：Slave_IO_Running: No或者Slave_SQL_Running: No</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#停掉slave服务"><span class="nav-number">3.1.1.</span> <span class="nav-text">停掉slave服务</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决办法"><span class="nav-number">3.1.2.</span> <span class="nav-text">解决办法</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#启动slave服务"><span class="nav-number">3.1.3.</span> <span class="nav-text">启动slave服务</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#再次查看Slave-IO-Running、Slave-SQL-Running状态，为Yes则表明设置成功。"><span class="nav-number">3.1.4.</span> <span class="nav-text">再次查看Slave_IO_Running、Slave_SQL_Running状态，为Yes则表明设置成功。</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#问题2：RROR-1198-HY000-This-operation-cannot-be-performed-with-a-running-slave-run-STOP-SLAVE-first"><span class="nav-number">3.2.</span> <span class="nav-text">问题2：RROR 1198 (HY000): This operation cannot be performed with a running slave; run STOP SLAVE first</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#PS："><span class="nav-number">3.3.</span> <span class="nav-text">PS：</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">失落的乐章</span>
</div>


<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Muse
  </a>
</div>


        

        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.1"></script>



  


  




	





  





  





  






  





  

  

  

  

  

  

</body>
</html>
